//
//  UILabel+HJ.m
//  CSC
//
//  Created by 黄杰 on 15/5/29.
//
//

#import "UILabel+HJ.h"

@implementation UILabel (HJ)

- (void)alignTop
{
    NSMutableDictionary *attr = [NSMutableDictionary dictionary];
    [attr setValue:self.font forKey:NSFontAttributeName];
    CGSize fontSize =[self.text sizeWithAttributes:attr];
    double finalHeight = fontSize.height *self.numberOfLines;
    double finalWidth =self.frame.size.width;//expected width of label
    CGSize theStringSize =[self.text sizeWithFont:self.font constrainedToSize:CGSizeMake(finalWidth, finalHeight) lineBreakMode:self.lineBreakMode];
    int newLinesToPad =(finalHeight - theStringSize.height)/ fontSize.height;
    for(int i=0; i<newLinesToPad; i++)
        self.text =[self.text stringByAppendingString:@"\n "];
}

@end
